// 权限按钮

import { FC, ReactNode } from "react";
import { useAppSelector } from "@/hooks";

interface AuthButtonProps {
  auth: string;
  children: ReactNode;
}

const AuthButton: FC<AuthButtonProps> = ({ auth, children }) => {
  // 从仓库里面取出 permissions
  const permissions = useAppSelector((state) => state.user.permissions);

  // 判断 auth 是否在 permissions 中
  if (permissions.includes(auth)) {
    // 有权限，直接 return children
    return children;
  } else {
    // 没有权限，返回一个 null
    return null;
  }
};

export default AuthButton;
